layui.use(['form', 'table', 'layer', 'upload','xmSelect'], function () {
    var $ = layui.jquery,
        form = layui.form,
        xmSelect = layui.xmSelect,
        upload = layui.upload;


    form.on('submit(saveCardToolFront)', function (datas) {
        saveCardToolFront();
    });
    form.on('submit(saveCardToolBack)', function (datas) {
        saveCardToolBack();
    });

    uploadImg(upload);
    /** 编辑窗结束 */

});

/**上传头像*/
function uploadImg(upload){
    upload.render({
        elem: '#imageUpload' //绑定元素
        , url: dl_coder_url.blog_uploadImg[0] //上传接口
        ,
        headers: {"token": headerMap.token},
        field: dl_coder_url.blog_uploadImg[2],
        force: "JSON",
        //上传展示图片
        done: function (result) {
            $('.blogMeImg').empty();
            $('.blogMeImg').append('<a href="javascript:void(0);" onclick="openImg();"><input name="headerImg"  id="headerImg" value="'+ result.data.img+'" style="display: none;"/> <img  id="showHeaderImg" src="' + result.data.imgShow  + '" width="200px"></a>');
        }
        , error: function () {
            //请求异常回调
        }
    });
}

/*查看大图*/
function openImg() {
    var idBar = '#showHeaderImg';
    var src = $(idBar)[0].src;
    var width = $(idBar).width();
    var height = $(idBar).height();
    var scaleWH = width / height;
    var bigH = 550;
    var bigW = scaleWH * bigH;
    if (bigW > 1000) {
        bigW = 1000;
        bigH = bigW / scaleWH;
    } // 放大预览图片
    parent.layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        shadeClose: true,
        area: [bigW + 'px', bigH + 'px'], //宽高
        content: '<img width="' + bigW + '" src="' + src + '" />'
    });
}


function saveCardToolFront() {
    var formData = $(".cardToolInfo").serializeJson();
    downloadAjax(dl_coder_url.tool_card_front[0], dl_coder_url.tool_card_front[1], formData);
}

function saveCardToolBack() {
    var formData = $(".cardToolInfo").serializeJson();
    downloadAjax(dl_coder_url.tool_card_back[0], dl_coder_url.tool_card_back[1], formData);
}

